﻿using System.Windows;
using System.Windows.Controls;
using WpfValidatorDemo;

namespace WpfValidatorDemo;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private MainViewModel? _viewModel;

    public MainWindow()
    {
        InitializeComponent();

        // 获取ViewModel实例
        _viewModel = DataContext as MainViewModel;

        // 添加密码框的密码变更事件处理
        if (PasswordBox != null)
        {
            PasswordBox.PasswordChanged += PasswordBox_PasswordChanged;
        }
    }

    private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
    {
        // 将密码框的值同步到ViewModel
        if (_viewModel != null && sender is PasswordBox passwordBox)
        {
            _viewModel.Password = passwordBox.Password;
        }
    }
}